function test() {
	console.log('middleware');
}

function t() {
	return async (ctx, next) => {
		console.log('test start');
		console.log(ctx);
		// 执行中间件方法 test
		test()
		// 执行完毕后执行下一个
		await next()
		console.log('test end');
	}
}
// 跨域中间件
// function cross(options) {
// 	return (ctx, next) => {
// 		ctx.set('Access-Control-Allow-Origin', options.allowOrigin.join(','))
// 		ctx.set('Access-Control-Allow-Methods', options.allowMethods.join(','))
// 		ctx.set('Access-Control-Allow-Headers', options.allowHeaders.join(','))
// 		ctx.set('Access-Control-Allow-Credentials', options.allowCredentials);
// 		next()
// 	}
// }

function routerResponse(opt = {}) {
	return async (ctx, next) => {
		ctx.succ = function(data,msg) {
			ctx.body = {
				code: opt.successCode || 200,
				msg: msg || opt.successMsg || 'Success',
				data: data || ''
			}
		}
		ctx.fail = function(msg, code) {
			ctx.body = {
				code: code || opt.failCode || 1,
				msg: msg || opt.failMsg || 'Error'
			}
		}
		await next()
	}
}
// function verifyToken(){
// 	return async (ctx,next)=>{
// 		console.log('middleware');
// 		const token = ctx.headers.authorization
// 		if(token){
// 			console.log('验证token结果',token);
// 			await next()
// 		}
// 		await next()
// 	}
// }
module.exports = {
	routerResponse,
}
